package com.briup.pts.service.impl;

import com.briup.pts.domain.bean.QuarantineRegistration;
import com.briup.pts.mapper.QuarantineMapper;
import com.briup.pts.service.QuarantineService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 25095
 * @description
 * @data 2024/11/26-17:25
 */
@Service
@RequiredArgsConstructor
public class QuarantineServiceImpl implements QuarantineService {

    private final QuarantineMapper mapper;

    @Override
    public PageInfo<QuarantineRegistration> pageQueryByCondition(String bQualified, String grMechanism,
                                                                 Integer pageNum, Integer pageSize) {
        try (Page<QuarantineRegistration> ignored = PageHelper.startPage(pageNum, pageSize)) {
            // 根据条件查询数据库中的数据
            List<QuarantineRegistration> categories = mapper.queryPage(bQualified, grMechanism);

            // 将查询的结果数据放入到PageInfo中返回
            return new PageInfo<>(categories);
        }
    }
    @Override
    public void deleteById(Integer grId) {
        mapper.deleteById(grId);
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
        mapper.deleteBatch(ids);
    }

    @Override
    public void saveOrUpdate(QuarantineRegistration qr) {
        // 根据质检报告id是否存在，决定是新增还是修改
        if (qr.getGrId() == null) {
            // 新增
            mapper.addQr(qr);
        } else {
            // 修改
            mapper.updateQr(qr);
        }
    }
}
